export enum LOG_LEVEL {
    LOG = "LOG",
    WARN = "WARN",
    ERROR = "ERROR"
}

enum LOG_LEVEL_IDX {
    LOG = 0,
    WARN = 1,
    ERROR = 2
}

export default class Logger {
    private static _enable: boolean = true;
    private static _logLevel: LOG_LEVEL = LOG_LEVEL.LOG;

    public static Init(enable: boolean = true, logLevel: LOG_LEVEL = LOG_LEVEL.LOG) {
        this.Enable(enable);
        this.LogLevel(logLevel);
    }

    public static Enable(enable: boolean = true) {
        this._enable = enable;
    }

    public static LogLevel(logLevel: LOG_LEVEL) {
        this._logLevel = logLevel;
    }

    public static Log(...data: any[]) {
        this._Log(LOG_LEVEL.LOG, ...data);
    }

    public static Warn(...data: any[]) {
        this._Log(LOG_LEVEL.WARN, ...data);
    }

    public static Error(...data: any[]) {
        this._Log(LOG_LEVEL.ERROR, ...data);
    }

    private static _Log(logLevel: LOG_LEVEL, ...data: any[]) {
        if (!this._enable) {
            return;
        }

        if (LOG_LEVEL_IDX[logLevel] < LOG_LEVEL_IDX[this._logLevel]) {
            return;
        }

        let method = LOG_LEVEL[logLevel].toLowerCase();
        console[method](...data);
    }
}

// 快捷函数
export function llog(...data: any[]) {
    Logger.Log(...data);
}

export function lwarn(...data: any[]) {
    Logger.Warn(...data);
}

export function lerror(...data: any[]) {
    Logger.Error(...data);
}
